package com.gnerv.battle.rabbitmq.agent.common.model;

import lombok.Data;

/**
 * @author Gnerv LiGen
 */
@Data
public class Result<T> {

    private Integer code;
    private String message;
    private T data;

    public Result() {
        this.code = ResultCode.CODE_200.getKey();
        this.message = ResultCode.CODE_200.getDesc();
    }

    public Result(ResultCode resultCode) {
        this.code = resultCode.getKey();
        this.message = resultCode.getDesc();
    }

    public static<T> Result<T> ok() {
        return new Result<>();
    }

    public static<T> Result<T> error(ResultCode resultCode) {
        return new Result<>(resultCode);
    }

    public static<T> Result<T> error(ResultCode resultCode, String message) {
        Result<T> result = new Result<>(resultCode);
        result.message = message;
        return result;
    }

    public static<T> Result<T> data(T data) {
        Result<T> result = new Result<>();
        result.data = data;
        return result;
    }

}
